﻿/*
 * Utility.h
 */

#ifndef __GDK_UTILITY_H__
#define __GDK_UTILITY_H__


#include <gdk/core/Types.h>
#include <gdk/core/String.h>



namespace gdk
{


	//////////////////////////////////////////////////////////////
	__INLINE__ uint32_t hashValue32(void const *data, ssize_t size)
	{
		const uint8_t *p = (const uint8_t *)data;
		uint32_t result = 0;

		for (ssize_t i = 0; i < size; ++i)
		{
			result += ((*p++) << ((i % 6) * 5));
		}

		return result == 0 ? (uint32_t)-1 : result;
	}
	__INLINE__ uint16_t hashValue16(void const *data, ssize_t size)
	{
		const uint8_t *p = (const uint8_t *)data;
		uint32_t result = 0;

		for (ssize_t i = 0; i < size; ++i)
		{
			result += ((*p++) << ((i % 3) * 5));
		}

		return (uint16_t)(result == 0 ? -1 : result);
	}


	//////////////////////////////////////////////////////////////
	__INLINE__ bool isEqual(float a, float b, float tolerance = 1e-06)
	{
		float d = a - b;
		return ( -tolerance < d ) && ( d < tolerance );
	}
	__INLINE__ bool isEqual(double a, double b, double tolerance = 1e-015)
	{
		double d = a - b;
		return (-tolerance < d) && (d < tolerance);
	}


	//////////////////////////////////////////////////////////////
	GDK_CORE_EXPORT String getAppName(void);
	GDK_CORE_EXPORT String getAppPath(void);



}//namespace gdk


#endif //__GDK_UTILITY_H__
